/**
 * Created by lwy on 2017/7/4.
 */

function GetQueryString(name)
{
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null) return  unescape(r[2]); return null;
}

var id = GetQueryString('id');
function doAjax(){
    $.ajax({
        url:'/crm/tiXianC/details.json',
        dataType:'json',
        data:{
            token:localStorage.getItem('crmtoken'),
            id:id,
        },
        type:'post',
        success:function(data){
            if(data.code==-1){
                window.parent.location.href="/crm/login.jsp"
            }
            if(data.code==0){
                alert(data.msg);
            }
            if(data.code==1){
                var data = data.datas;
                $('#cname').val(data.accountName);
                $('#cardNum').val(data.cardNum);
                $('#code').val(data.code);
                $('#createTime').val(data.createTime);
                $('#applyMoney').val(data.money);
                $('#service').val(data.factorage);
                $('#state').val(data.state);
                if(data.state=='待审核'){
                    if(data.isTheWeek==1){
                        $('#agreeBox').hide();
                        $('#handlerTimeBox').show();
                        $('#seal').show();
                    }
                    if(data.isTheWeek==0){
                        $('#agreeBox').show();
                        $('#handlerTimeBox').hide();
                        $('#seal').hide();
                    }
                }else{
                    $('#agreeBox').hide();
                    $('#handlerTime').val(data.handTime);
                    $('#handlerTimeBox').show();
                }
                $('#handler').val(data.handUserName);
                $('#kaihuhag').val(data.kaihuhang);

            }
        }
    })
}
$(function(){
    doAjax();
})


$('#agree').unbind(); //移除所有
$('#agree,#noagree').click(function(){
    $.ajax({
        url:'/crm/tiXianC/checkUpdate.json',
        dataType:'json',
        type:'post',
        data:{
            token:localStorage.getItem('crmtoken'),
            id:id,
            stateValue:$(this).attr('value'),
            note:$('#tips').val(),
        },
        success:function(data){
            if(data.code==-1){
                window.parent.location.href="/crm/login.jsp"
            }
            if(data.code==0){
                alert(data.msg);
            }
            if(data.code==1){
                alert('处理成功');
                doAjax();
            }
        }
    })
})